<template>
	<div class="SGgoodsadd ">
		<div class="my-app">
			<h2 class="my-h2">商品管理 / 添加产品</h2>
			<list-nav></list-nav>
			<div class=" my-form-item">
				<div class="content">
					<goods-add></goods-add>
					<div class="my-button">
						<el-button class="submit" @click="AddScenicPrice">
							提交
						</el-button>
					</div>
				</div>
			</div>
		</div>
	</div>
</template>

<script>
	import {
		mapGetters,
		mapActions
	} from 'vuex';
	import ListNav from "../../../components/ListNav.vue";
	import GoodsAdd from "../../../components/GoodsAdd.vue";
	export default {
		data() {
			return {
				id: this.$route.query.id,
				NavName: "商品管理  /  添加产品",
				tablist: {
					isactive: 1,
					list: [{
						id: 1,
						name: "成人票",
					}, {
						id: 2,
						name: "套票",
					}, {
						id: 3,
						name: "优待票",
					}, ]
				},
				addAduilList: {
					row: 1,
					list: [{
						label: "结束时间",
						name: "",
						tiempicker: true,
						tiemval: "",
					}, {
						label: "开始时间",
						name: "",
						tiempicker: true,
						tiemval: "",
					}, ]
				},
				addWellList: [{
					label: "优待人群",
					name: "",
					wellstatus: true,
					well: {
						checkList: ["儿童"],
						list: ["儿童", "学生", "老年人", "军人", "教师", "残疾人"]
					},
				}, ],
				AdultList: [{
						label: "价格类型",
						name: "",
						text: "price_type",
						elradiostatus: true,
						elradio: {
							radio: 1,
							list: ["默认价格", "活动价格"],
							label: [1, 2]
						},
					}, {
						label: "开始时间",
						name: "",
						text: "start_time",
						show: false,
						tiempicker: true,
						tiemval: "",
					},
					{
						label: "结束时间",
						name: "",
						text: "end_time",
						show: false,
						tiempicker: true,
						tiemval: "",
					}, {
						label: "优待人群",
						name: "",
						wellstatus: true,
						show: true,
						well: {
							checkList: [],
							list: ["儿童", "学生", "老年人", "军人", "教师", "残疾人"]
						},
					},
					{
						label: "产品名称",
						text: "type_name",
						name: "",
						text: "type_name",
						textsta: true,
						buttonStart: false,
						buttonText: "",
						showpassword: false
					},
					{
						label: "门市价格",
						name: "",
						text: "scenic_listing_price",
						textsta: true,
						buttonStart: false,
						buttonText: "",
						showpassword: false
					},
					{
						label: "会员价格",
						name: "",
						text: "scenic_membership_price",
						textsta: true,
						buttonStart: false,
						buttonText: "",
						showpassword: false
					},
					{
						label: "结算价格",
						name: "",
						text: "scenic_settlement_price",
						textsta: true,
						buttonStart: false,
						buttonText: "",
						showpassword: false
					},
					{
						label: "是否上架",
						name: "",
						text: "status",
						elradiostatus: true,
						elradio: {
							radio: "",
							list: ["上架产品", "下架产品"],
							label: [1, 2]
						},
					},
					{
						label: "适用条件",
						name: "",
						text: "apply",
						textarea: "textarea",
					},
					{
						label: "使用说明",
						name: "",
						text: "use_explain",
						textarea: "textarea",
					},
				],
				ScenicPrice: {
					token: "", //	String	 header传入
					status: "", //	Number	 1上架,2下架 允许值: 1, 2
					price_type: "", //	Number	 1默认价格,2活动价格 允许值: 1, 2
					start_time: "", // String 开始时间（ 默认价格为 ''）
					end_time: "", // String 介绍时间（ 默认价格为 ''）
					type: "成人票", // String 商品分类
					type_name: "", // String 商品名称
					discount_type: "", // String 优待票分类
					scenic_listing_price: "", // Number 景区门市价
					scenic_membership_price: "", // Number 景区会员价
					scenic_settlement_price: "", // Number 景区结算价
					apply: "", // String 请填写适用条件
					use_explain: "", // String 使用说明
				},
			}
		},
		computed: {
			...mapGetters([
				'token',
				'LabelInput',
				"ListNavData",
				'pcAddScenicPrice',
				'edit_productList'
			])
		},
		components: {
			ListNav,
			GoodsAdd
		},
		created() {
			let req_ScenicPrice = JSON.parse(JSON.stringify(this.pcAddScenicPrice)); //this.templateData是父组件传递的对象
			this.AdultList[1].show = true;
			this.AdultList[2].show = true;
			req_ScenicPrice.start_time = "";
			req_ScenicPrice.end_time = "";
			req_ScenicPrice.price_type = 1;
			this.getPcAddScenicPrice(req_ScenicPrice)
		},
		mounted() {
			if (this.id != undefined) {
				for (var i = 0; i < this.tablist.list.length; i++) {
					if (this.edit_productList.type === this.tablist.list[i].name) {
						this.tablist.isactive = this.tablist.list[i].id;
						this.tablist.pointerevents = true;
						if (this.tablist.isactive === 3) {
							this.AdultList[3].show = false;
						} else {}

					}
				}
				if (this.edit_productList.price_type === 1) {
					this.AdultList[1].show = true;
					this.AdultList[2].show = true;
				}
				if (this.edit_productList.price_type === 2) {
					this.AdultList[1].show = false;
					this.AdultList[2].show = false;
				}
				this.ScenicPrice = {
					id: this.id,
					status: this.edit_productList.status, //	Number	 1上架,2下架 允许值: 1, 2
					price_type: this.edit_productList.price_type, //	Number	 1默认价格,2活动价格 允许值: 1, 2
					start_time: this.edit_productList.start_time, // String 开始时间（ 默认价格为 ''）
					end_time: this.edit_productList.end_time, // String 介绍时间（ 默认价格为 ''）
					type: this.edit_productList.type, // String 商品分类
					type_name: this.edit_productList.type_name, // String 商品名称
					discount_type: this.edit_productList.discount_type, // String 优待票分类
					scenic_listing_price: this.edit_productList.scenic_listing_price, // Number 景区门市价
					scenic_membership_price: this.edit_productList.scenic_membership_price, // Number 景区会员价
					scenic_settlement_price: this.edit_productList.scenic_settlement_price, // Number 景区结算价
					apply: this.edit_productList.apply, // String 请填写适用条件
					use_explain: this.edit_productList.use_explain, // String 使用说明
				}
				this.getPcAddScenicPrice(this.ScenicPrice)
				this.AdultList[0].elradio.radio = this.edit_productList.price_type; //价格类型：
				this.AdultList[0].pointerevents = true; //房间名称：
				this.AdultList[1].tiemval = this.edit_productList.start_time; //开始时间
				this.AdultList[1].pointerevents = true; //房间名称：
				this.AdultList[2].tiemval = this.edit_productList.end_time; //结束时间
				this.AdultList[2].pointerevents = true; //房间名称：
				this.AdultList[3].well.checkList = this.edit_productList.discount_type;
				this.AdultList[3].pointerevents = true; //房间名称：
				this.AdultList[4].name = this.edit_productList.type_name; //产品名称
				this.AdultList[4].pointerevents = true; //房间名称：
				this.AdultList[5].name = this.edit_productList.scenic_listing_price; //门市价格
				this.AdultList[6].name = this.edit_productList.scenic_membership_price; //会员价格
				this.AdultList[7].name = this.edit_productList.scenic_settlement_price; //结算价格
				// this.AdultList[7].pointerevents = true; //房间名称：
				this.AdultList[8].elradio.radio = this.edit_productList.status; //是否上架：
				this.AdultList[9].name = this.edit_productList.apply; //适用条件
				this.AdultList[10].name = this.edit_productList.use_explain; //使用说明
			}
			this.setLabelInput(this.AdultList)
			this.setListNavData(this.tablist);
		},
		watch: {
			LabelInput: {
				handler(newValue, oldValue) {
					var that = this;
					for (let i = 0; i < newValue.length; i++) {
						if (newValue[i].elradiostatus === true) {}
					}
				},
				deep: true
			},
		},
		methods: {
			...mapActions({
				setLabelInput: "setLabelInput",
				setListNavData: "setListNavData",
				getPcAddScenicPrice: "getPcAddScenicPrice",
				getSidebarNavIndex: 'getSidebarNavIndex'
			}),
			AddScenicPrice() {
				let req_ScenicPrice = JSON.parse(JSON.stringify(this.pcAddScenicPrice)); //this.templateData是父组件传递的对象
				req_ScenicPrice["token"] = this.token;
				if (this.id === undefined)
					delete req_ScenicPrice["id"]
				this.getPcAddScenicPrice(req_ScenicPrice)
				this.$api.GetpcAddScenicPrice(this.pcAddScenicPrice)
					.then(res => {
						this.$alert(res.meg, '提示', {
							confirmButtonText: '确定',
							callback: action => {
								if (res.code === 200) {
									this.$router.push("/SGgoodsselect")
									this.getSidebarNavIndex("SGgoodsselect")
								}
							}
						});


					})
			},
			getsondata_tab(res) {
				if (res === 3) {
					this.AdultList[3].show = false;
				} else {
					this.AdultList[3].show = true;
				}
			},
			getcheckboxlist(res) {
				let req_ScenicPrice = JSON.parse(JSON.stringify(this.pcAddScenicPrice)); //this.templateData是父组件传递的对象
				req_ScenicPrice.discount_type = res.well.checkList;
				this.getPcAddScenicPrice(req_ScenicPrice)
			},
			gettypenav(res) {
				let req_ScenicPrice = JSON.parse(JSON.stringify(this.pcAddScenicPrice)); //this.templateData是父组件传递的对象
				req_ScenicPrice.type = res.name;
				if (res.id != 3) {
					req_ScenicPrice.discount_type = "";
				}
				this.getPcAddScenicPrice(req_ScenicPrice)
			},
			gettimepicker(res) {
				let req_ScenicPrice = JSON.parse(JSON.stringify(this.pcAddScenicPrice)); //this.templateData是父组件传递的对象
				req_ScenicPrice[res.text] = res.tiemval;
				this.getPcAddScenicPrice(req_ScenicPrice)
			},
			getsondata_radio(res) {
				let req_ScenicPrice = JSON.parse(JSON.stringify(this.pcAddScenicPrice)); //this.templateData是父组件传递的对象
				if (res.text === "price_type") {
					if (res.elradio.radio === 1) {
						this.AdultList[1].show = true;
						this.AdultList[2].show = true;
						req_ScenicPrice.start_time = "";
						req_ScenicPrice.end_time = "";
					}
					if (res.elradio.radio === 2) {
						this.AdultList[1].show = false;
						this.AdultList[2].show = false;
					}
				}
				this.setLabelInput(this.AdultList)
				req_ScenicPrice[res.text] = res.elradio.radio;
				this.getPcAddScenicPrice(req_ScenicPrice)
			},
			getchangetext(res) {
				let req_ScenicPrice = JSON.parse(JSON.stringify(this.pcAddScenicPrice)); //this.templateData是父组件传递的对象
				req_ScenicPrice[res.text] = res.name;
				this.getPcAddScenicPrice(req_ScenicPrice)
			},
		},

	}
</script>

<style lang="less">
	.SGgoodsadd {
		width: 100%;
		padding: 0 10px;
		box-sizing: border-box;




		.submit-box {
			width: 100%;
			padding-left: 130px;
			box-sizing: border-box;


		}


	}
</style>
